package com.cryptape.cita_wallet.service;

import android.content.res.Configuration;
import android.content.res.Resources;
import android.util.DisplayMetrics;

import com.cryptape.cita_wallet.CytonApplication;

import java.util.Locale;

/**

 */

public class LanguageUtils {
//    private static LanguageKeeper mLanguageKeeper;
    private static String mDefaultType;
    public static Resources resources;

    private static Resources getResourse() {
//        mLanguageKeeper = new LanguageKeeper(CytonApplication.getInstance());
        mDefaultType = LanguageKeeper.getInstance().getLanguage(CytonApplication.getInstance());
        resources = CytonApplication.getInstance().getResources();
        Configuration config = resources.getConfiguration();

        switch (mDefaultType) {
            case LanguageKeeper.LANGUAGE_CN:
                config.locale = Locale.CHINESE;
                break;
            case LanguageKeeper.LANGUAGE_EN:
                config.locale = Locale.ENGLISH;
                break;
            case LanguageKeeper.LANGUAGE_JA:
                config.locale = Locale.JAPANESE;
                break;
            case LanguageKeeper.LANGUAGE_KO:
                config.locale = Locale.KOREAN;
                break;
            default:
                config.locale = Locale.getDefault();
        }
        DisplayMetrics dm = resources.getDisplayMetrics();
        resources.updateConfiguration(config, dm);
        return resources;
    }


    public static String getString(int id) {
        if (resources != null) {
            return resources.getString(id);
        }else {
            return getResourse().getString(id);
        }
    }
}
